/* 
 * @description: 全局信息封装
 * @author: Jane 
 * @date: 2023-09-13 09:38:30
 */
import 'package:package_info_plus/package_info_plus.dart';
import 'common_exports.dart';
import 'local_storage.dart';

class GlobalInfo {
  /// 应用包名
  static String packageName = '';
  // 构建版本号
  static String buildNum = '';

  /// 应用版本F
  static String version = '';
  static Future<void> initPlatformState() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    packageName = packageInfo.packageName;
    version = packageInfo.version;
    buildNum = packageInfo.buildNumber;
    print("版本号信息=====${packageInfo.toString()}");
  }

  /// 是否有token
  static bool isHasToken() {
    String token = LocalStorage.get("accessToken") ?? '';
    bool isLogin = LocalStorage.get("isLogin") ?? false;
    return token.isNotEmpty && isLogin ? true : false;
  }

  static logoutApp() async {
  // 触发登出事件
      EventBusManager.instance.commit(EventKeys.logout);

  }

  /// 退出登录
  static exitApp() async {
    bool token = await LocalStorage.remove('accessToken');
    bool islogin = await LocalStorage.remove("isLogin");
    if (token && islogin) {
      LocalStorage.cleanAll();
      Get.offNamedUntil(AppRoutes.login, (route) => false);
    }
  }
}
